package com.fjc.mapper;

import com.fjc.annotation.AutoFill;
import com.fjc.dto.AdminPageQueryDTO;
import com.fjc.entity.Admin;
import com.fjc.enumeration.OperationType;
import com.github.pagehelper.Page;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

@Mapper
public interface AdminMapper {
    /**
     * 根据用户名查询管理员
     * @param username
     * @returnd
     */
    @Select("select * from home_medicine_cabinet.admin where username = #{username}")
    Admin getByUsername(String username);

    /**
     * 插入管理员数据
     * @param admin
     */
    @AutoFill(value = OperationType.INSERT)
    @Insert("insert into home_medicine_cabinet.admin (name, username, password, phone, sex, id_number, create_time, update_time, create_user, update_user) " +
            "values" +
            "(#{name}, #{username}, #{password}, #{phone}, #{sex}, #{idNumber}, #{createTime}, #{updateTime}, #{createUser}, #{updateUser})")
    void insert(Admin admin);

    /**
     * 分页查询
     * @param adminPageQueryDTO
     * @return
     */
    Page<Admin> pageQuery(AdminPageQueryDTO adminPageQueryDTO);

    /**
     * 根据主键动态修改属性
     * @param admin
     */
    @AutoFill(value = OperationType.UPDATE)
    void update(Admin admin);

    /**
     * 根据id查询管理员信息
     * @return
     */
    @Select("select * from home_medicine_cabinet.admin where id = #{id}")
    Admin getById(long id);
}
